package se.webbzon.boltzmann.game.object.dialogue.word;

import java.awt.Color;

import se.webbzon.boltzmann.game.object.dialogue.AbstractDialogue;
import se.webbzon.boltzmann.game.object.dialogue.layout.DialogueLayout;
import se.webbzon.boltzmann.game.sequence.Sequences;

public class DynamicDialogueWord extends SimpleDialogueWord {
	
	// The color of the dynamic dialogue word
	private static final Color color = new Color(0,128,0);
	
	// The key to the string of this word
	private final String str;

	/*============================================================
	Constructors
	============================================================*/
	
	public DynamicDialogueWord(DialogueLayout layout, String str) {
		super(layout, "", color);
		this.str = str;
	}

	/*============================================================
	Public Methods
	============================================================*/
	
	@Override public void onUpdateWord(AbstractDialogue dialogue) {
		Object value = Sequences.parse(dialogue.getSequence(), str);
		if (value instanceof Double) {
			Double d = (Double) value;
			if (Math.floor(d) == d)
				value = d.intValue();
		}
		setWord(value.toString());
	}

}
